﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class admin_add : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["name"] == null)
            {
                Response.Write("<script>alert('非法登录!!!');window.top.location='../Login.aspx';</script>");
                return;
            }
            else
            {
                BindData();
            }
            
        }
    }

    //数据绑定
    protected void BindData()
    {
        string selectstr = "select * from tb_picture order by pic_ID desc";
            DataTable dt = OleDbHelper.GetDataTable(selectstr);
            gv_scenery.DataSource = dt;
            gv_scenery.DataBind();
    }

    //自动编号
    protected void gv_scenery_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowIndex != -1)
        {
            int sort = e.Row.RowIndex + 1;
            e.Row.Cells[0].Text = sort.ToString();
        }
    }
    //分页
    protected void gv_scenery_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gv_scenery.PageIndex = e.NewPageIndex;
        BindData();
    }

    //删除用户
    protected void lb_delete_Click(object sender, EventArgs e)
    {
        LinkButton btn = (LinkButton)sender;
        int id = int.Parse(btn.CommandArgument.ToString());
        string deletestr = "delete from tb_picture where pic_ID=@pic_ID";
        OleDbParameter[] param = { 
                                     new OleDbParameter("pic_ID",id)
                                 };
        int flag = OleDbHelper.ExecuteNonSql(deletestr, param);
        if (flag > 0)
        {
            Page.ClientScript.RegisterStartupScript(GetType(), "提示", "<script>alert('删除成功！')</script>");
            BindData();
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(GetType(), "提示", "<script>alert('删除失败！')</script>");
        }
    }
}